package net.sxnic.ugr.menu.action;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

@SuppressWarnings("serial")
public class Save extends MenuAction {

	private static Log log = LogFactory.getLog(Save.class);

	private String id;

	public void prepare() throws Exception {
		if(StringUtils.isNotBlank(id))
			menu = menuManager.get(id);
	}
	
	public String execute() throws Exception {
		try {
			if (StringUtils.isBlank(menu.getId()))
				menuManager.save(menu);
			else
				menuManager.update(menu);
			
			msg = "saveSuccess";

		} catch (Exception e) {
			e.printStackTrace();
		}

		return SUCCESS;
	}

	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}
}
